package net.zoneland.knowledge.service.impl;

import java.util.HashMap;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;

import net.zoneland.knowledge.model.LoginUserPojo;
import net.zoneland.knowledge.service.AuthService;

/**
 * mock实现任务.
 *
 * @author: bcc
 *     2022/3/11
 */
@ConditionalOnProperty(name = "biz.auth-method", havingValue = "mock")
@Service
public class AuthServiceImplMock implements AuthService {
    private static Map<String, LoginUserPojo> userMap = new HashMap<>();

    @Override
    public LoginUserPojo getLoginUser(final HttpServletRequest request) {
        //后台根据userId取角色，userId要有角色

        // aihua，艾华
        // zhaoxinc，赵欣晨
        // caixq，蔡晓琼
        // zxf，赵杏芳
        // jif，季芳
        // zhangyu23，张妤

        return userMap.get("zxf");
    }

    @Override
    public String getUserId(final HttpServletRequest request) {
        return getLoginUser(request).getUserID();
    }

    /**
     * 构造测试用户.
     * @return
     */
    @PostConstruct
    public void preparedUsers() {
        //后台根据userId取角色，userId要有角色
        LoginUserPojo jif = new LoginUserPojo();
        jif.setUserID("jif");
        jif.setUserName("季芳");
        jif.setDepartmentDN("OU=党委办公室（党群工作部）,O=zmcc");
        jif.setDeptName("党委办公室（党群工作部）");
        jif.setUserIdCard("E0022000104");
        setCommonField(jif);
        userMap.put("jif", jif);

        LoginUserPojo caixq = new LoginUserPojo();
        caixq.setUserID("caixq");
        caixq.setUserName("蔡晓琼");
        caixq.setDepartmentDN("OU=党委办公室（党群工作部）,O=zmcc");
        caixq.setDeptName("党委办公室（党群工作部）");
        caixq.setUserIdCard("E0022003292");
        setCommonField(caixq);
        userMap.put("caixq", caixq);

        LoginUserPojo aihua = new LoginUserPojo();
        aihua.setUserID("aihua");
        aihua.setUserName("艾华");
        aihua.setDepartmentDN("OU=党委办公室（党群工作部）,O=zmcc");
        aihua.setDeptName("党委办公室（党群工作部）");
        aihua.setUserIdCard("E0022005796");
        setCommonField(aihua);
        userMap.put("aihua", aihua);

        LoginUserPojo zxf = new LoginUserPojo();
        zxf.setUserID("zxf");
        zxf.setUserName("赵杏芳");
        zxf.setDepartmentDN("OU=党委办公室（党群工作部）,O=zmcc");
        zxf.setDeptName("党委办公室（党群工作部）");
        zxf.setUserIdCard("E0022000387");
        setCommonField(zxf);
        userMap.put("zxf", zxf);

        LoginUserPojo zhangyu23 = new LoginUserPojo();
        zhangyu23.setUserID("zhangyu23");
        zhangyu23.setUserName("张妤");
        zhangyu23.setDepartmentDN("OU=党委办公室（党群工作部）,O=zmcc");
        zhangyu23.setDeptName("党委办公室（党群工作部）");
        zhangyu23.setUserIdCard("E0022005950");
        setCommonField(zhangyu23);
        userMap.put("zhangyu23", zhangyu23);

        LoginUserPojo zhaoxinc = new LoginUserPojo();
        zhaoxinc.setUserID("zhaoxinc");
        zhaoxinc.setUserName("赵欣晨");
        zhaoxinc.setDepartmentDN("OU=人力资源部,O=zmcc");
        zhaoxinc.setDeptName("人力资源部");
        zhaoxinc.setUserIdCard("E0022001087");
        setCommonField(zhaoxinc);
        userMap.put("zhaoxinc", zhaoxinc);

        LoginUserPojo nich = new LoginUserPojo();
        nich.setUserID("nich");
        nich.setUserName("倪重晖");
        nich.setDepartmentDN("OU=党委办公室（党群工作部）,O=zmcc");
        nich.setDeptName("党委办公室（党群工作部）");
        nich.setUserIdCard("E0022002845");
        setCommonField(nich);
        userMap.put("nich", nich);
    }

    public void setCommonField(LoginUserPojo userPojo) {
        userPojo.setEmail("demo@demo.zoneland.com");
        userPojo.setMobilePhone("13812888888");
        userPojo.setCompanyDN("O=zmcc");
        userPojo.setCompanyName("省公司");
        userPojo.setAdminOrgDn("O=zmcc");
        userPojo.setAdminOrgName("省公司");
    }

    @Override
    public boolean isMock() {
        return true;
    }

}
